/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.persistance;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author genis
 */
public class SettingsDataManager {

    private File defaults;
    private File settings;
    private File checks;
    public SettingsDataManager(String path) {
        defaults = new File(path+"defaults");
        settings = new File(path+"settings");
        checks = new File(path+"checks");
    }

    public String [] loadSettings(boolean def) throws FileNotFoundException {
        Scanner sc;
        if (def) {
            sc = new Scanner(defaults);
        } else {
            sc = new Scanner(settings);
        }
        String [] setts = new String[8];

        for (int i = 0; sc.hasNextLine() && i < 8; ++i) {
            setts[i] = sc.nextLine();
        }

        sc.close();
        
        return setts;
    }

    public String [] loadChecks() throws FileNotFoundException {
        Scanner sc = new Scanner(checks);
        String [] c = new String [3];
        for (int i = 0; sc.hasNextLine() && i < 8; ++i) {
            c[i] = sc.nextLine();
        }
        return c;
    }

    public void saveSettings(String [] setts) throws IOException {
        if (settings.exists()) {
            settings.delete();
        }

        settings.createNewFile();

        FileWriter flw = new FileWriter(settings);
        BufferedWriter bw = new BufferedWriter(flw);

        for (int i = 0; i < setts.length; ++i) {
            bw.write(setts[i]);
            bw.newLine();
        }
        bw.close();
    }
    public void saveChecks(String [] c) throws IOException {
        if (checks.exists()) {
            checks.delete();
        }

        checks.createNewFile();

        FileWriter flw = new FileWriter(checks);
        BufferedWriter bw = new BufferedWriter(flw);

        for (int i = 0; i < c.length; ++i) {
            bw.write(c[i]);
            bw.newLine();
        }
        bw.close();
    }
}
